"""
给你两个字符串：ransomNote 和 magazine ，
判断 ransomNote 能不能由 magazine 里面的字符构成。
如果可以，返回 true ；否则返回 false 。
magazine 中的每个字符只能在 ransomNote 中使用一次。
"""


def canConstruct(ransomNote: str, magazine: str) -> bool:
    dic = {}
    for i in magazine:
        if i in dic:
            dic[i] = dic[i] + 1
        else:
            dic[i] = 1
    for i in ransomNote:
        if i not in dic:
            return False
        else:
            dic[i] = dic[i] - 1
            if dic[i] < 0:
                return False
    return True


if __name__ == '__main__':
    ransomNote = "aa"
    magazine = "aab"
    print(canConstruct(ransomNote, magazine))
